<?php
/* @var $this NhomlopController */
/* @var $model Nhomlop */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'nhomlop-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Điền đầy đủ vào vị trí có dấu <span class="required">*</span>.</p>

	<?php echo $form->errorSummary($model); ?>
<table>

	<div class="row">
	<tr>
		<td><?php echo $form->labelEx($model,'makhoilop'); ?></td>
		<td><?php 
			$connection=Yii::app()->db;   // assuming you have configured a "db" connection
			$command=$connection->createCommand()
			->select('makhoilop')
			->from('thongtinsv')
			//->where(array('and','username="'.$this->username.'"','level>0'))
			->query();
			$khoilop= array();
			foreach($command as $row)
			{
				//array_push($ngach,$row);
				$khoilop[$row['makhoilop']]=$row['makhoilop'];
			}
		echo $form->dropDownList($model,'makhoilop',$khoilop,array('id'=>'makhoilop','empty'=>'')); ?></td>
		<td><?php echo $form->error($model,'makhoilop'); ?></td>
	</tr>
	</div>

	<div class="row">
	<tr>
		<td><?php echo $form->labelEx($model,'mamh'); ?></td>
		<td><?php 
			$connection=Yii::app()->db;   // assuming you have configured a "db" connection
			$command=$connection->createCommand()
			->select('mamh,tenmh')
			->from('monhoc')
			//->where(array('and','username="'.$this->username.'"','level>0'))
			->query();
			$hocphan= array();
			foreach($command as $row)
			{
				//array_push($ngach,$row);
				$hocphan[$row['mamh']]=$row['tenmh'];
			}
			
		echo $form->dropDownList($model,'mamh',array(),array('id'=>'mamh','empty'=>'')); ?></td>
		<td><?php echo $form->error($model,'mamh'); ?></td>
	</tr>
	</div>

	<div class="row">
	<tr>
		<td><?php echo $form->labelEx($model,'soSV'); ?></td>
		<td><?php echo $form->textField($model,'soSV'); ?></td>
		<td><?php echo $form->error($model,'soSV'); ?></td>
	</tr>
	</div>

	<div class="row">
	<tr>
		<td><?php echo $form->labelEx($model,'hocki'); ?></td>
		<td><?php echo $form->dropDownList($model,'hocki',array('1'=>'1','2'=>'2','3'=>'Hè')); ?></td>
		<td><?php echo $form->error($model,'hocki'); ?></td>
	</tr>
	</div>

	<div class="row">
	<tr>
		<td><?php echo $form->labelEx($model,'ghichu'); ?></td>
		<td><?php echo $form->textArea($model,'ghichu',array('rows'=>6, 'cols'=>50)); ?></td>
		<td><?php echo $form->error($model,'ghichu'); ?></td>
	</tr>
	</div>
</table>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tạo mới' : 'Lưu'); ?>
	</div>
	<?php

 
?>
	<script type="text/javascript">
	$(document).ready(function(){
		var initial_target_html = '<option value="">Chọn khối lớp</option>';
		$('#mamh').html(initial_target_html);
		setValueMH($("#makhoilop").val());
		
		$("#makhoilop").change(function(){
			var selectvalue = $(this).val();
			$("#mamh").empty();
			$('#mamh').html('<option value="">Loading...</option>');
			//$('#mamh').html('<option value=""></option>');
			setValueMH(selectvalue);
		});
		function setValueMH(selectvalue) {
			if (selectvalue == "") {
				//Display initial prompt in target select if blank value selected
			    $('#mamh').html(initial_target_html);
			} else {
				//Make AJAX request, using the selected value as the GET
				$.ajax({url: 'ajax-getvalues.php?makhoilop='+selectvalue,
					success: function(output) {
						//alert(output);
						$('#mamh').html(output);
					},
					error: function (xhr, ajaxOptions, thrownError) {
						alert(xhr.status + " "+ thrownError);
					}});
			}
			
		}
	/*$('#Nhomlop_makhoilop').change(function(){
		alert(this.val());
	});*/
	});
	</script>
<?php $this->endWidget(); ?>

</div><!-- form -->